home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14557 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: ix.netcom.com!news
  2. From: jlilley@ix.netcom.com (John Lilley)
  3. Newsgroups: comp.lang.c++,ualberta.cmput.201
  4. Subject: Re: class/function pointer help!
  5. Date: 30 Mar 1996 23:46:42 GMT
  6. Organization: Netcom
  7. Message-ID: <4jkh52$i4b@dfw-ixnews6.ix.netcom.com>
  8. References: <4jhlk7$1eke@pulp.ucs.ualberta.ca>
  9. NNTP-Posting-Host: den-co15-25.ix.netcom.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-NETCOM-Date: Sat Mar 30  5:46:42 PM CST 1996
  13. X-Newsreader: WinVN 0.99.7
  14.  
  15. In article <4jhlk7$1eke@pulp.ucs.ualberta.ca>, ryangall@gpu.srv.ualberta.ca 
  16. says...
  17. >
  18. >Hi, I have a class that uses a function pointer. The problem Im having is 
  19. >that the pointer doesnt want to access the function when the function is a 
  20. >local function to the calling class. Here is what I mean....
  21. >
  22. >class expression
  23. >    {
  24. >      public:
  25. >         string S;
  26. >         list L;
  27. >         int   initlist();
  28. >         int   isexpr(int);
  29. >    };
  30. >
  31. >
  32. >list, and string are both classes.
  33. >
  34. >char * string::POP( int (* separator)(int c) );
  35. >
  36. >this works when I define isexpr(int) globally, but I want to beable to 
  37. >call function expression::isexpr(int).....when I do this...
  38. >
  39. >  while((temp=S.POP( isexpr )))
  40. >  {
  41. >
  42. > the compiler say:" member function must be called or its address taken."
  43. >
  44. >how do I declare the member function as a function pointer?!
  45.  
  46. First things first.  Member functions are not the same as functions and are 
  47. interchangeable under no circumstances (although you can get away with it if 
  48. they are static).  The reason is that member functions have an implciit "this" 
  49. argument, and the mechanism for passing that argument is undefined.  It makes 
  50. no sense to call a member function by pointer unless you have an object to 
  51. call it with.
  52.  
  53. You *can* use a pointer-to-member-function, but you also have to supply the 
  54. object to invoke it on....
  55.  
  56. john lilley
  57.  
  58.  
  59.  
  60.